package tgc.rj.garbage;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import tgc.rj.garbage.custom.ToastUtils;
import tgc.rj.garbage.functionfragment.Exhibitgoods_fragment;
import tgc.rj.garbage.functionfragment.Xuanxiang2_Fragment;
import tgc.rj.garbage.functionfragment.Xuanxiang3_Fragment;
import tgc.rj.garbage.functionfragment.Xuanxiang4_Fragment;

public class CommodityActivity extends AppCompatActivity implements View.OnClickListener {
    private LinearLayout lin1,lin2,lin3,lin4;
    private Exhibitgoods_fragment exfragment;
    private Xuanxiang2_Fragment xuan2fragment;
    private Xuanxiang3_Fragment xuan3fragment;
    private Xuanxiang4_Fragment xuan4fragment;
    private TextView xuanxiang1,xuanxiang2,xuanxiang3,xuanxiang4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_commodity);
        xuanxiang1 = findViewById(R.id.xuanxiang1);
        xuanxiang2 = findViewById(R.id.xuanxiang2);
        xuanxiang3 = findViewById(R.id.xuanxiang3);
        xuanxiang4 = findViewById(R.id.xuanxiang4);
        lin1 = findViewById(R.id.lin1);
        lin2 = findViewById(R.id.lin2);
        lin3 = findViewById(R.id.lin3);
        lin4 = findViewById(R.id.lin4);
        xuanxiang1.setOnClickListener(this);
        xuanxiang2.setOnClickListener(this);
        xuanxiang3.setOnClickListener(this);
        xuanxiang4.setOnClickListener(this);
        xuanxiang1.performClick();
    }

    @Override
    public void onClick(View v) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        switch (v.getId()){
            case R.id.xuanxiang1:
                if(exfragment == null){
                    exfragment = new Exhibitgoods_fragment();
                }
                transaction.replace(R.id.fragment_containar , exfragment);
                lin1.setBackgroundResource(R.color.colorRee);
                lin2.setBackgroundResource(R.color.colorBac);
                lin3.setBackgroundResource(R.color.colorBac);
                lin4.setBackgroundResource(R.color.colorBac);
                break;
            case R.id.xuanxiang2:
                if(xuan2fragment == null){
                    xuan2fragment = new Xuanxiang2_Fragment();
                }
                transaction.replace(R.id.fragment_containar ,xuan2fragment);
                lin2.setBackgroundResource(R.color.colorRee);
                lin1.setBackgroundResource(R.color.colorBac);
                lin3.setBackgroundResource(R.color.colorBac);
                lin4.setBackgroundResource(R.color.colorBac);
                break;
            case R.id.xuanxiang3:
                if(xuan3fragment == null){
                    xuan3fragment = new Xuanxiang3_Fragment();
                }
                transaction.replace(R.id.fragment_containar,xuan3fragment);
                lin3.setBackgroundResource(R.color.colorRee);
                lin1.setBackgroundResource(R.color.colorBac);
                lin2.setBackgroundResource(R.color.colorBac);
                lin4.setBackgroundResource(R.color.colorBac);
                break;
            case R.id.xuanxiang4:
                if(xuan4fragment ==null){
                    xuan4fragment = new Xuanxiang4_Fragment();
                }
                transaction.replace(R.id.fragment_containar,xuan4fragment);
                lin4.setBackgroundResource(R.color.colorRee);
                lin1.setBackgroundResource(R.color.colorBac);
                lin2.setBackgroundResource(R.color.colorBac);
                lin3.setBackgroundResource(R.color.colorBac);

                break;
        }
        transaction.commit();
    }

    public void cleanColor(){

        xuanxiang1.setBackgroundResource(R.color.colorBac);
        xuanxiang2.setBackgroundResource(R.color.colorBac);
        xuanxiang3.setBackgroundResource(R.color.colorBac);
        xuanxiang4.setBackgroundResource(R.color.colorBac);
    }
}
